package com.ftx.controller.test.annotation.autowire;

import com.ftx.controller.test.annotation.value.Person;
import org.junit.Test;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

/**
 * Created by fengtingxin on 2020/4/22.
 */
public class IOCTest_Autowire {


    @Test
    public void test01(){
        AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(MainConfigofAutowired.class);
        System.out.println("容器创建完成");
        printBeans(applicationContext);
//        BookService bookService = applicationContext.getBean(BookService.class);
//        System.out.println(bookService);

//        BookDao bookDao = (BookDao)applicationContext.getBean("bookDao");

//        System.out.println(bookDao);

        PersonAutoWire personAutoWire = applicationContext.getBean(PersonAutoWire.class);
        System.out.println(personAutoWire);
        System.out.println(applicationContext);


    }


    private void printBeans(AnnotationConfigApplicationContext applicationContext){
        String[] names = applicationContext.getBeanDefinitionNames();
        for ( String name : names){
            System.out.println(name);
        }

    }
}
